<?php
class Schedule extends CI_Controller{
    function __construct(){
            parent::__construct();
            // Your own constructor code  
    }
    function index(){
         $this->load->view('schedule/schedule_body');
    }

    function get_weeknum_by_date(){
        if(isset($_POST['submit'])){
            $date=implode('-', array($_POST['year'],$_POST['month'],$_POST['day']));
            $this->load->Model("model_date");
            echo $weeknum=$this->model_date->get_weeknum_by_date($date);
            
        }
    }


    function open_new_week(){
        // $weeknum_today=$this->Model_date->get_weeknum_of_today();
        // $weeknum_array=$this->Model_date->get_weeknum_of_year_array();
        // $date_of_today=date('y-m-d');

        // $date['weeknum_today']=$weeknum_today;
        // $date['weeknum_array']=$weeknum_array;
        // $date['date_of_today']=$date_of_today;


        // $this->load->view('schedule/open_new_week.php',$date);
        //     if(isset($_POST['open'])){
        //         $weeknum=$_POST['weeknum'];
        //         $this->load->model('Model_schedule');
        //         $result=$this->Model_schedule->open_new_week($weeknum);
        //         if($result){
        //             echo 'success';
        //         }else{
        //             echo 'no.';
        //     }
        
    }
    function get_weekly_schedule(){
        if(isset($_GET['weeknum'])){
            $weeknum=$_GET['weeknum'];
            $this->load->model('Model_schedule');
            $result_set=$this->Model_schedule->get_weekly_schedule(2012,$weeknum);

            $data['query']=$result_set;
            $data['date_info']=$this->Model_schedule->get_weekly_date(2012,$weeknum);
             
            if(isset($_POST['search'])){
                $date=(string)$_POST["date"];
                $time=(string)$_POST["time"].":00:00 ";
                $array=array($date,$time);
                $datetime=  implode(' ', $array);
                $this->load->model('Model_schedule');
                $detail=$this->Model_schedule->get_detail($datetime);
                $data['detail']=$detail;
            }
            $this->load->view('schedule/schedule_body',$data);
        }
    }  
}
?>

